/** =====================================================
 * Copyright © hk. 2022-2025. All rights reserved.
 * File name  : aes_core.h
 * Author     : 苏木
 * Date       : 2024-08-12
 * Version    : 
 * Description: 
 * ======================================================
 */

#ifndef __AES_CORE_H
#define __AES_CORE_H

//#define OPENSSL_AES_CONST_TIME
//#define AES_ASM

//数据类型定义
typedef unsigned char       u8; /**< UNSIGNED  8-bit data type */
typedef unsigned short     u16; /**< UNSIGNED 16-bit data type */
typedef unsigned int       u32; /**< UNSIGNED 32-bit data type */
typedef unsigned long long u64; /**< UNSIGNED 64-bit data type */
typedef signed char         s8; /**<   SIGNED  8-bit data type */
typedef signed short       s16; /**<   SIGNED 16-bit data type */
typedef signed int         s32; /**<   SIGNED 32-bit data type */
typedef signed long long   s64; /**<   SIGNED 64-bit data type */

#define AES_BLOCK_SIZE  (16)
#define AES_ENCRYPT     (1)
#define AES_DECRYPT     (0)
#define AES_MAXNR       (14)
#define OK              (0)

#undef GETU32
#define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] <<  8) ^ ((u32)(pt)[3]))
#define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >>  8); (ct)[3] = (u8)(st); }

/* This should be a hidden type, but EVP requires that the size be known */
struct aes_key_st {
#ifdef AES_LONG
    unsigned long rd_key[4 * (AES_MAXNR + 1)];
#else
    unsigned int rd_key[4 * (AES_MAXNR + 1)];
#endif
    int rounds;
};
typedef struct aes_key_st AES_KEY;

int func_aes_secret_key_config(unsigned char *userKey, int length, int flg);
int func_aes_encrypt_pack(unsigned char *expkey, unsigned char *encrypt_data, int size);
int func_aes_decrypt_pack(unsigned char *expkey, unsigned char *encrypt_data, int size);

#endif